package nl.tudelft.jpacman.level;


import nl.tudelft.jpacman.npc.Ghost;
import nl.tudelft.jpacman.points.PointCalculator;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.*;


public class PlayerCollisionsTest {
    private PlayerCollisions playerCollisions;
    private PointCalculator pointCalculator;

    @BeforeEach
    void set(){
        pointCalculator=mock(PointCalculator.class);
        playerCollisions=new PlayerCollisions(pointCalculator);

    }

    @Test
    @DisplayName("撞到鬼")
    void playerCollideGhost01(){
        Player player01=mock(Player.class);
        Ghost ghost=mock(Ghost.class);

        playerCollisions.collide(player01,ghost);
        verify(pointCalculator).collidedWithAGhost(player01,ghost);
        verify(player01).setAlive(false);
        verify(player01).setKiller(ghost);

    }

    @Test
    @DisplayName("碰到豆子")
    void playerCollideOnPellet(){

        Player player01=mock(Player.class);
        Pellet pellet=mock(Pellet.class);
        playerCollisions.collide(player01,pellet);
        verify(pointCalculator).consumedAPellet(player01,pellet);
        verify(pellet).leaveSquare();

    }

    @Test
    @DisplayName("鬼碰撞撞到玩家")
    void ghostCollideOnPlayer(){
        Player player01=mock(Player.class);
        Ghost ghost=mock(Ghost.class);

        playerCollisions.collide(ghost,player01);
        verify(pointCalculator).collidedWithAGhost(player01,ghost);
        verify(player01).setAlive(false);
        verify(player01).setKiller(ghost);
    }

    @Test
    @DisplayName("豆子撞到了玩家")
    void pelletCollideOnPlayer(){
        Player player01=mock(Player.class);
        Pellet pellet=mock(Pellet.class);
        playerCollisions.collide(pellet,player01);
        verify(pointCalculator).consumedAPellet(player01,pellet);
        verify(pellet).leaveSquare();
    }

    @Test
    @DisplayName("碰撞无效")
    void collideWithoutResult() {
        Player player01 = mock(Player.class);
        Ghost ghost = mock(Ghost.class);
        Pellet pellet = mock(Pellet.class);
//        规则5，鬼碰撞鬼
        playerCollisions.collide(ghost, ghost);
//        规则6，鬼碰撞豆子
        playerCollisions.collide(ghost, pellet);
//        规则7，豆碰撞鬼
        playerCollisions.collide(pellet, ghost);




        verify(player01,times(0)).setAlive(false);
        verify(player01,times(0)).setKiller(ghost);
        verify(pellet,times(0)).leaveSquare();

    }

}
